package com.xunyin.enums;

/**
 * @author jthong
 * @Description:APPID-Key映射
 * @Version 1.0.0
 * @Date 2020/10/30 15:33
 */
public enum AppIdKeyEnum {
    /***
     * 查询4路继电器状态
     */
    XUNYIN("wx6345a04c42ae10e3", "1c06fda90b3b2c27a35cc603ea02679d");

    private final String appId;
    private final String appKey;

    AppIdKeyEnum(String appId, String appKey) {
        this.appKey = appKey;
        this.appId = appId;
    }

    public String getAppId() {
        return appId;
    }

    public String getAppKey() {
        return appKey;
    }

    public String getIndex() {
        return appId;
    }

    public static AppIdKeyEnum parse(String appId) {
        if (appId == null) {
            return throwParseException(appId);
        }
        for (AppIdKeyEnum e : AppIdKeyEnum.values()) {
            if (appId.equals(e.getAppId())) {
                return e;
            }
        }
        return throwParseException(appId);
    }

    private static AppIdKeyEnum throwParseException(String appId) {
        throw new IllegalArgumentException(appId + " can not parse to " + AppIdKeyEnum.class.getName());
    }

    public static String getAppKeyByAppId(String appId) {
        if (appId == null) {
            return "";
        }
        for (AppIdKeyEnum e : AppIdKeyEnum.values()) {
            if (appId.equals(e.getAppId())) {
                return e.getAppKey();
            }
        }
        return "";
    }
}
